#pragma once

#include <QObject>
class QTcpSocket;
class TcpSocket : public QObject
{
	Q_OBJECT

public:
    TcpSocket(QTcpSocket* sock = nullptr, QObject* parent = nullptr);
    ~TcpSocket();
    bool IfConnected();
    bool ConnectToServer(const QString& host, unsigned int port);
    void Disconnect();
    bool WriteData(const QByteArray& data);
    bool WaitForWritten(int ms);

signals:
    void DataReady(const QByteArray& data);
    void Disconnected();

private slots:
    void OnReadyRead();

private:
    QTcpSocket* socket;
};
